package com.atguigu.spzx.cart.controller;

import com.atguigu.spzx.cart.service.CartService;
import com.atguigu.spzx.model.entity.cart.CartInfo;
import com.atguigu.spzx.model.vo.common.Result;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author LT
 * @create 2024-03-28-15:43
 */
@RestController
@RequestMapping("/api/order/cart")
public class CartController {

    @Autowired
    private CartService cartService;

    @GetMapping("/auth/clearCheckedCart")
    public Result clearCheckedCart(){
        cartService.clearCheckedCart();
        return Result.ok();
    }



    @GetMapping("/auth/allCheckCart")
    public Result<List<CartInfo>> getallCheckCart(){
        List<CartInfo> list = cartService.getAllCkecked();
        return Result.ok(list);
    }

    @GetMapping("/auth/allCheckCart/{isChecked}")
    public Result allCheckCart(@PathVariable("isChecked") Integer isChecked){
        cartService.allCheckCart(isChecked);
        return Result.ok();
    }


    @GetMapping("/auth/checkCart/{skuId}/{isChecked}")
    public Result checkCart(@PathVariable("skuId") Integer skuId,
                            @PathVariable("isChecked") Integer isChecked){
        cartService.checkCart(skuId,isChecked);
        return Result.ok();
    }

    @GetMapping("/auth/clearCart")
    public Result clearCart(){
        cartService.clearCart();
        return Result.ok();
    }

    @DeleteMapping("/auth/deleteCart/{skuId}")
    public Result deleteCart(@PathVariable("skuId") Long skuId){
        cartService.deleteCart(skuId);
        return Result.ok();
    }

    @GetMapping("/auth/cartList")
    public Result cartList(){
         List<CartInfo> cartInfos = cartService.cartList();
         return Result.ok(cartInfos);
    }


    @GetMapping("/auth/addToCart/{skuId}/{skuNum}")
    public Result<T> addToCart(@PathVariable("skuId") Long skuId,
                               @PathVariable("skuNum") Integer skuNum){
        cartService.addToCart(skuId,skuNum);
        return Result.ok();
    }

}
